package com.answeringplayer.controller;

import com.answeringplayer.Bean.Request;
import com.answeringplayer.Bean.Response;
import com.answeringplayer.domain.User;
import com.answeringplayer.dto.LoginDTO;
import com.answeringplayer.dto.UserDTO;
import com.answeringplayer.service.LoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/api/auth/")
public class LoginController {

    @Autowired
    LoginService loginService;

    @PostMapping("mock-login")
    public Response<LoginDTO> login(@RequestBody Request<UserDTO> request) {
        // --- 添加调试日志 ---
        System.out.println("=== 接收到登录请求 ===");
        System.out.println("Request Data: " + request.getData());
        if (request.getData() != null) {
            System.out.println("Username from DTO: " + request.getData().getUsername());
            System.out.println("Password from DTO: " + request.getData().getPassword());
            System.out.println("Email from DTO: " + request.getData().getEmail()); // 检查 email
        }
        System.out.println("=====================");

        return loginService.login(request);
    }
    
    @PostMapping("register")
    public Response<LoginDTO> register(@RequestBody Request<UserDTO> request) {
        // --- 添加调试日志 ---
        System.out.println("=== 接收到注册请求 ===");
        System.out.println("Request Data: " + request.getData());
        if (request.getData() != null) {
            System.out.println("Username from DTO: " + request.getData().getUsername());
            System.out.println("Password from DTO: " + request.getData().getPassword());
            System.out.println("Nickname from DTO: " + request.getData().getNickname());
        }
        System.out.println("=====================");

        return loginService.register(request);
    }
}
